package com.easybuy.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.easybuy.sys.model.SysStoreMessage;
import com.easybuy.sys.mapper.SysStoreMessageMapper;
import com.easybuy.sys.service.SysStoreMessageService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author SR.Y
 * @since 2020-12-05
 */
@Service
public class SysStoreMessageServiceImpl extends ServiceImpl<SysStoreMessageMapper, SysStoreMessage> implements SysStoreMessageService {

    @Override
    public boolean create(SysStoreMessage storeMessage) {
        return save(storeMessage);
    }

    @Override
    public boolean update(SysStoreMessage storeMessage) {
        return updateById(storeMessage);
    }

    @Override
    public boolean getState(Integer id) {
        QueryWrapper<SysStoreMessage> wrapper = new QueryWrapper<SysStoreMessage>();
        LambdaQueryWrapper<SysStoreMessage> lambda = wrapper.lambda();
        if (id != null) {
            lambda.eq(SysStoreMessage::getUid, id);
        }
        SysStoreMessage storeMessage = getOne(wrapper);
        Integer state = storeMessage.getState();
        return 0 != state;
    }

    @Override
    public Page<SysStoreMessage> list(Integer state, Integer pageSize, Integer pageNum) {
        Page<SysStoreMessage> page = new Page<>(pageNum, pageSize);
        QueryWrapper<SysStoreMessage> wrapper = new QueryWrapper<>();
        LambdaQueryWrapper<SysStoreMessage> lambda = wrapper.lambda();
        if (state != null) {
            lambda.like(SysStoreMessage::getState, state);
        }
        return page(page);
    }


}
